package com.foreknow.elm.service.impl;

import com.foreknow.elm.dao.UserDao;
import com.foreknow.elm.dao.impl.UserDaoImpl;
import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.util.DBUtil;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {
    @Override
    public User getUserByIdByPass(String userId, String password) {
        User user = new User();
        UserDao userDao = new UserDaoImpl();

        try {
            user = userDao.getUserByIdByPass(userId,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close();
        }
        return user;
    }

    @Override
    public int getUserById(String userId) {
        int i = 0;
        UserDao userDao = new UserDaoImpl();
        try {
            i = userDao.getUserById(userId);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close();
        }
        return i;
    }

    @Override
    public int saveUser(String userId, String password, String userName, Integer userSex) {
        int i = 0;
        UserDao userDao = new UserDaoImpl();
        try {
            i = userDao.saveUser(userId,password,userName,userSex);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close();
        }
        return i;
    }
}
